from time import sleep

from celery_tasks.celery import app
from meiduo_mall.libs.yuntongxun.sms import CCP


@app.task(bind=True)
def send_smscode(self,mobile,sms_code):
    # sleep(20)
    # 云通讯
    ccp = CCP()
    # 注意： 测试的短信模板编号为1
    try:
        result = ccp.send_template_sms(mobile, [sms_code, 5], 1)
    except Exception as e:
        result = -1

    # 失败的话重新发送
    if result == -1:
        self.retry(exc=Exception('发送短信失败'),countdown=5,max_retries=3)